package com.jp.knowledge.fragment;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import com.jp.knowledge.model.OrganizeInfoModel;
import com.jp.knowledge.model.PositionKnowlegeMode;

/**
 * Created by 528787067@qq.com on 2017/8/15.
 */

public class OrganizeKnowledgeSelectDetailFragment extends AdjustSortTypeDetailFragment {

	public static OrganizeKnowledgeSelectDetailFragment newInstance(PositionKnowlegeMode data){
		OrganizeKnowledgeSelectDetailFragment fragment = new OrganizeKnowledgeSelectDetailFragment();
		Bundle bundle = new Bundle();
		bundle.putSerializable("data", data);
		fragment.setArguments(bundle);
		return fragment;
	}

	@Override
	public void onItemClick(int mainPosition, int subPosition) {
		if(itemClickListener != null){
			OrganizeInfoModel.KnowledgeBean data = new OrganizeInfoModel.KnowledgeBean();
			PositionKnowlegeMode.ListBeanX.ListBean bean = OrganizeKnowledgeSelectDetailFragment.this.
					data.getList().get(mainPosition).getList().get(subPosition);
			data.setCateId(bean.getId());
			data.setCateName(bean.getName());
			if(itemClickListener.onItemClick(data, !bean.isSelect())){
				bean.setSelect(!bean.isSelect());
				adapter.notifyItemChanged(mainPosition);
			}
		}
	}

	private ItemClickListener itemClickListener;

	public void setItemClickListener(ItemClickListener itemClickListener){
		this.itemClickListener = itemClickListener;
	}

	public interface ItemClickListener{
		boolean onItemClick(OrganizeInfoModel.KnowledgeBean data, boolean isSelected);
	}
}
